package com.example.service;

import com.example.mapper.*;
import com.example.pojo.dto.CollectDTO;
import com.example.pojo.dto.DriverDTO;
import com.example.pojo.entity.JobRecruiter;
import com.example.pojo.entity.Post;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 本文来演示
 *
 * @author 赵建云
 * @create 2023/10/12
 */
@Service
public class DriverServiceImpl implements DriverService{
    @Autowired
    private CollectService collectService;
    @Autowired
    private DriverMapper driverMapper;
    @Autowired
    private PostMapper postMapper;
    @Autowired
    private JobSeekerMapper jobSeekerMapper;
    @Autowired
    private JobRecruiterMapper jobRecruiterMapper;
    @Autowired
    private MessageMapper messageMapper;
    @Autowired
    private CollectMapper collectMapper;

    @Override
    public List<CollectDTO> findAlreadyList(Integer jsId) {
        List<CollectDTO> list = new ArrayList<>();
        List<Integer> posIds = driverMapper.already(jsId);
        for (Integer posId : posIds) {
            Post post = postMapper.findAllByPostId(posId);
            CollectDTO collectDTO = new CollectDTO();
            collectDTO.setPosId(post.getId());
            collectDTO.setPosName(post.getPosName());
            collectDTO.setExpDemand(post.getExpDemand());
            collectDTO.setRecruitsNum(post.getRecruitsNum());
            collectDTO.setWorkPlace(post.getWorkPlace());
            Integer jrId = post.getJrId();
            collectDTO.setJrId(jrId);
            JobRecruiter jobRecruiter = jobRecruiterMapper.fingJobRecruiterById(jrId);
            collectDTO.setCompanyName(jobRecruiter.getCompanyName());
            collectDTO.setJrAvatar(jobRecruiter.getJrAvatar());
            collectDTO.setContactPerson(jobRecruiter.getContactPerson());
            if (post.getBackground().equals("0")){
                collectDTO.setBackground("不限");
            }else if (post.getBackground().equals("1")){
                collectDTO.setBackground("本科");
            }else if (post.getBackground().equals("2")){
                collectDTO.setBackground("硕士");
            }else {
                collectDTO.setBackground("博士");
            }
            if (null!=post.getPayFloor()&&post.getPayFloor()>=1000){
                collectDTO.setPay(post.getPayFloor()/1000+"k"+"-"+post.getPayUpper()/1000+"k");
            }else {
                collectDTO.setPay(post.getPayFloor()+"元"+"-"+post.getPayUpper()+"元");
            }
            collectDTO.setCompanyType(jobRecruiter.getCompanyType());
            list.add(collectDTO);
        }
        return list;
    }

    @Override
    public PageInfo<CollectDTO> findAlready(Integer pageNum,Integer pageSize,Integer jsId) {
        PageInfo<CollectDTO> pageInfo = null;
        Page<CollectDTO> page = PageHelper.startPage(pageNum,pageSize);
        List<CollectDTO> list = findAlreadyList(jsId);
        pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public DriverDTO findJobFromChat(Integer jsId) {
        int messageNum = messageMapper.messageNumById(jsId);
        int interviewNum=driverMapper.interviewNumById(jsId);
        int driverNum = driverMapper.driverNumById(jsId);
        int collectNum = collectMapper.collectNumById(jsId);
        DriverDTO driverDTO = new DriverDTO();
        driverDTO.setInterviewNum(interviewNum);
        driverDTO.setSubmitNum(driverNum);
        driverDTO.setAddNum(messageNum);
        driverDTO.setInterestNum(collectNum);
        return driverDTO;
    }
}
